<template>
  <div>
    <div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a :class="['mui-control-item',item.id==0?'mui-active':'']" v-for="item in category" :key="item.id"
              @click="getPhotosListByCateId(item.id)">
							{{item.title}}
						</a>
					</div>
				</div>

			</div>

      <!-- 图片列表 -->
      <ul class="photolist">
        <!-- 使用route-link的tag属性指定要渲染成什么标签 -->
       <router-link v-for="item in list" :key="item.id" :to="'/home/photoInfo/'+item.id" tag="li">
        <img v-lazy="item.img_url">
        <div class="info">
          <h1 class="info_title">{{ item.title }}</h1>
          <div class="info_con">{{ item.zhaiyao }}</div>
        </div>
       </router-link>
      </ul>
  </div>
</template>
<script>
import mui from "../../lib/mui/js/mui.min.js";

export default {
  data() {
    return {
      category: [],
      list: []
    };
  },
  created() {
    this.getAllCategory();
    /* 默认显示全部页 */
    this.getPhotosListByCateId(0);
  },
  mounted() {
    /* 初始化滑动条组件 放在mounted中，当进入图片列表时，即可滚动 */
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    getAllCategory() {
      this.$http.get("api/getimgcategory").then(result => {
        if (result.body.status == 0) {
          result.body.message.unshift({ title: "全部", id: 0 });
          this.category = result.body.message;
        }
      });
    },
    getPhotosListByCateId(cateId) {
      this.$http.get("api/getimages/" + cateId).then(result => {
        if (result.body.status == 0) {
          this.list = result.body.message;
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
* {
  touch-action: pan-y; /* 去除滑动条滑动时的警告 */
}

.photolist {
  list-style: none;
  margin: 0;
  padding: 10px;
  padding-bottom: none;
  li {
    background-color: #ccc;
    text-align: center;
    margin: 10px;
    /* 
    E {box-shadow:inset x-offset y-offset blur-radius spread-radius color} 换句说： 
    对象选择器 {box-shadow:投影方式 X轴偏移量 Y轴偏移量 阴影模糊半径 阴影扩展半径 阴影颜色}
    */
    box-shadow: 0 0 20px 5px #999;
    position: relative;
    img {
      width: 100%;
      /* 图片多出3px的问题 */
      vertical-align: middle;
    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
    .info {
      position: absolute;
      bottom: 0;
      text-align: left;
      /* z-index: 100; */
      background-color: rgba(0, 0, 0, 0.4);
      color: #fff;
      /* 超出内容的设置 显示3行*/
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 3;
      padding: 5px;

      .info_title {
        font-size: 16px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
      }
      .info_con {
        font-size: 14px;
      }
    }
  }
}
</style>
